﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MacNs
{
    public class MacToNameConverter
    {
        private Dictionary<string, string> _FriendlyNames = new Dictionary<string, string> ();

        public void Rebuild (System.Collections.Specialized.StringCollection aMappings)
        {
            _FriendlyNames.Clear ();
            foreach (string s in aMappings)
            {
                int p = s.IndexOf ('=');
                if (p > 0)
                {
                    string mac = s.Substring (0, p).Trim ();
                    string name = s.Substring (p + 1).Trim ();
                    _FriendlyNames.Add (mac, name);
                }
            }
        }

        public string Convert (string s)
        {
            string n;
            if (_FriendlyNames.TryGetValue (s, out n))
            {
                return n;
            }
            else
            {
                return s;
            }
        }

    }
}
